<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- wayland-and-qt.qdoc -->
  <title>Wayland and Qt | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Wayland and Qt</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#why-use-multi-process">Why Use Multi-Process</a></li>
<li class="level1"><a href="#why-use-wayland-instead-of-x11-or-custom-solutions">Why Use Wayland Instead of X11 or Custom Solutions</a></li>
<li class="level1"><a href="#possible-trade-offs-with-multi-process">Possible Trade-Offs with Multi-Process</a></li>
<li class="level1"><a href="#what-qt-wayland-offers">What Qt Wayland Offers</a></li>
<li class="level2"><a href="#related-content">Related Content</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Wayland and Qt</h1>
<span class="subtitle"></span>
<!-- $$$wayland-and-qt.html-description -->
<div class="descr"> <a name="details"></a>
<p><a href="https://wayland.freedesktop.org/">Wayland</a> is a display server protocol that helps you to create multi-process systems. Multiple client applications (&quot;clients&quot;) can render their own content to off-screen buffers. These buffers are then passed to a display server, often called a compositor, using the Wayland protocol. Finally, the compositor composites and positions the content on a physical display.</p>
<a name="why-use-multi-process"></a>
<h2 id="why-use-multi-process">Why Use Multi-Process</h2>
<p>In a single-process system, all parts of the UI run in one, single process. In a multi-process system, all clients run in their own, dedicated process. With Qt, at any point in your development process, you can choose to switch between single-process and multi-process.</p>
<p class="centerAlign"><img src="images/wayland-multi-process.png" alt="" /></p><p class="figCaption">Multi-Process Client Architecture</p>
<p class="centerAlign"><img src="images/wayland-single-process-eglfs.png" alt="" /></p><p class="figCaption">Single Process Client Architecture</p>
<p>The use of multi-process has the following benefits:</p>
<ul>
<li><a href="wayland-and-qt.html#stability">Stability</a></li>
<li><a href="wayland-and-qt.html#security">Security</a></li>
<li><a href="wayland-and-qt.html#performance">Performance</a></li>
<li><a href="wayland-and-qt.html#interoperability">Interoperability</a></li>
</ul>
<a name="stability"></a><div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th  colspan="2">Stability</th></tr></thead>
<tr valign="top" class="odd"><td >Easier to recover when clients hang or crash</td><td >If you have a complex UI, then multi-process is useful because if one part of the UI crashes, it doesn't affect the entire system. Similarly, the display won't freeze, even when one client freezes.<p><b>Note: </b>If your client is mandated by law to render safety-critical information, consider using <a href="https://doc.qt.io/QtSafeRenderer/qtsr-overview.html">Qt Safe Renderer Overview</a>.</p></td></tr>
<tr valign="top" class="even"><td >Protection against possible memory leaks</td><td >In a multi-process system, if one client has a memory leak and consumes lots of memory, that memory is recovered when that client exits. In contrast with single-process, the memory leak remains until the entire system restarts.</td></tr>
</table></div>
<a name="security"></a><div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th >Security</th></tr></thead>
<tr valign="top" class="odd"><td >In a single-process system, all clients can access each other's memory. For example, there's no isolation for sensitive data transfer; every line of code must be equally trustworthy. This isolation is there, by design, in multi-process systems.</td></tr>
</table></div>
<a name="performance"></a><div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th >Performance</th></tr></thead>
<tr valign="top" class="odd"><td >If you have a CPU with multiple cores, a multi-process system can help distribute the load evenly across different cores, making more efficient use of your CPU.</td></tr>
</table></div>
<a name="interoperability"></a><div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th >Interoperability</th></tr></thead>
<tr valign="top" class="odd"><td >You can interface with non-Qt clients in a multi-process system, as long as your clients understand Wayland or X11. For example, if you use gstreamer for video or if you want to use a navigation application built with another UI toolkit, you can run these clients alongside your other Qt-based clients.</td></tr>
</table></div>
<a name="why-use-wayland-instead-of-x11-or-custom-solutions"></a>
<h2 id="why-use-wayland-instead-of-x11-or-custom-solutions">Why Use Wayland Instead of X11 or Custom Solutions</h2>
<p>X11, a desktop protocol from the 80s, no longer fits with how graphics hardware works today. It is large, complex, and lacks customizability. In fact, it is difficult to run a client fluidly with X11, and reach 60 fps without tearing. Wayland, in contrast, is easier to implement, has better performance, and contains all the necessary parts to run efficiently on modern graphics hardware. For embedded, multi-process systems on Linux, Wayland is the standard.</p>
<p>However, if you are working with old hardware or legacy applications, then Wayland may not be a good option. The Wayland protocol is designed with security and isolation in mind, and is strict/conservative about what information and functionality is available to clients. While this leads to a cleaner and more secure interface, some functionality that legacy applications expect may no longer be available on Wayland.</p>
<p>Particularly, there are three common use cases where Wayland may not be the best option:</p>
<ol class="1" type="1"><li>The hardware or platform is old and only supports X11; in which case you have no choice.</li>
<li>You have to support legacy applications that depend on features that are absent in the Wayland protocol for security and simplicity.</li>
<li>You have to support legacy applications that use a UI toolkit that doesn't run on Wayland at all. In some cases, you may be able to work around this by running those applications on <a href="https://wayland.freedesktop.org/xserver.html">XWayland</a> instead.</li>
</ol>
<p>Back when X11 was very popular, developers wrote their own custom solutions to circumvent X11 issues. Older Qt versions had the Qt Windowing System (QWS), which is now discontinued. Today, most of these use cases are covered by Wayland, and custom solutions are becoming less and less common.</p>
<a name="possible-trade-offs-with-multi-process"></a>
<h2 id="possible-trade-offs-with-multi-process">Possible Trade-Offs with Multi-Process</h2>
<p>Use of multi-process systems do bring about the following trade-offs:</p>
<ul>
<li><a href="wayland-and-qt.html#increased-video-memory">Increased video memory consumption</a></li>
<li><a href="wayland-and-qt.html#increased-main-memory">Increased main memory consumption</a></li>
<li><a href="wayland-and-qt.html#repeated-storage">Repeated storage of graphical resources</a></li>
</ul>
<a name="increased-video-memory"></a><div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th >Increased video memory consumption</th></tr></thead>
<tr valign="top" class="odd"><td >This can be a constraint for embedded devices. In multi-process, each client needs to have its own graphics buffer, which it sends to the compositor. Consequently, you use more video memory compared to the single-process case: where everything is drawn at once and there is no need to store the different parts in intermediary buffers.</td></tr>
</table></div>
<a name="increased-main-memory"></a><div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th >Increased main memory consumption</th></tr></thead>
<tr valign="top" class="odd"><td >Apart from some extra overhead at the OS level, running multiple clients may also use more main memory as some parts need to be duplicated once per client. For example, if you run QML, each client requires a separate QML engine. Consequently, if you run a single client that uses Qt Quick Controls, it's loaded once. If you then split this client into multiple clients, you're loading Qt Quick Controls multiple times, resulting in a higher startup cost to initialize your clients.</td></tr>
</table></div>
<a name="repeated-storage"></a><div class="table"><table class="generic" width="100%">
 <thead><tr class="qt-style"><th >Repeated storage of graphical resources</th></tr></thead>
<tr valign="top" class="odd"><td >In a single-process system, if you're using the same textures, background, or icons in many places, those images are only stored once. In contrast, if you use these images in a multi-process system, then you have to store them multiple times. In this case, one solution is to share graphical resource between clients. Qt already allows sharing image resources in main memory across processes without involving Wayland. Sharing GPU textures across processes, on the other hand, requires more intricate solutions. Such solutions are currently in development for the Qt Wayland Compositor.</td></tr>
</table></div>
<a name="what-qt-wayland-offers"></a>
<h2 id="what-qt-wayland-offers">What Qt Wayland Offers</h2>
<p><b>For Clients</b> <br />
 Qt clients can run on any Wayland compositor, including Weston, the reference compositor developed as part of the Wayland project.</p>
<p>Any Qt program can run as a Wayland client (as part of a multi-process system) or a standalone client (single-process). This is determined on startup, where you can choose between the different backends. During the development process, you can develop the client on the desktop first, then test it on the target hardware later. You don't need to run your clients on the actual target hardware all the time.</p>
<p class="centerAlign"><img src="images/wayland-single-process-develop.png" alt="" /></p><p class="figCaption">Single-Process Client Development</p>
<p>If you develop on a Linux machine, you can also run the compositor within a window on your development machine. This lets you run clients in an environment that closely resembles the target device. Without rebuilding the client, you can also run it with <code>-platform wayland</code> to run it inside the compositor. If you use <code>-platform xcb</code> (for X11), you can run the client on the desktop. In other words, you can start developing your clients before the compositor is ready for use.</p>
<p><b>For Servers</b> <br />
 The server, or compositor, connects to the display and shows the contents of each client on the screen. The compositor handles input and sends input events to the corresponding client. In turn, each client connects to the compositor and sends the content of its windows. It's up to the compositor to decide:</p>
<ul>
<li>How and where to show the content</li>
<li>Which content to show</li>
<li>What to do with the different client graphics buffers</li>
</ul>
<p>This means, it's up to the compositor to decide what a multi-process system is. For instance, the clients could be part of a 3D scene with windows on the walls, on a VR system, mapped to a sphere, and so on.</p>
<p>The Qt Wayland Compositor is an API for building your own compositor. It gives you full freedom to build a custom compositor UI and manage the windows of various clients. You can combine both Qt Quick and QML with the Qt Wayland Compositor to create impressive, imaginative UIs. For more information, see <a href="license-changes.html#qt-wayland-compositor">Qt Wayland Compositor</a>.</p>
<a name="related-content"></a>
<h3 id="related-content">Related Content</h3>
<ul>
<li><a href="https://resources.qt.io/qt-world-summit-2017/qtws17-qt-wayland-compositor-creating-multi-process-user-interface-johan-helsing-the-qt-company">QtWS17 - Qt Wayland Compositor: Creating multi-process user interface</a></li>
<li><a href="https://doc.qt.io/QtApplicationManager/introduction.html">Qt Application Manager</a></li>
</ul>
</div>
<!-- @@@wayland-and-qt.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
